<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang quên mật khẩu</title>


<link href="../style/cs1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
if(isset($_POST["user"]))
{
	$user = $_POST["user"];
	include("config/config.php");
	if(isset($_POST["user"])=="")
	{
		?>
        <script>
		alert('Bạn chưa nhập user!');
		location.href="quenmatkhau.php";
		</script>
        <?php
		
	}
	else
	{
		$lenh = "select * from khachhang where user='$user'";
		$kq = mysql_query($lenh);
		$row = mysql_fetch_array($kq);
		if($row[0]!=0)
		{
			$mk = mt_rand();
			$mkmh = sha1(md5(md5($mk)));
			$to = $row["email"];
			$from = 'anhphuoc73@gmail.com';
			$sub = 'Lấy lại mật khẩu!';
			$mess = 'Mật khẩu mới của bạn là '.$mk;
			$head = 'Content-Type content=text/html; charset=utf-8'.'from'.$from."\r\n";
			mail($to,$sub,$mess,$head);
			$lenhsua = "update khachhang set matkhau='$mkmh' , xacnhanmatkhau='$mkmh' where user='$user'";
			$kqsua = mysql_query($lenhsua);
			if($kqsua)
			{
				?>
                <script>
				alert('Đã gởi mật khẩu mới vào mail của bạn!');
				</script>
                <?php
				
			}
		}
		else
		{
			?>
            <script>
			alert('Không có user này!');
			</script>
            <?php
			
		}
		
	}
}
	

?>
<form id="form1" name="form1" method="post" action="">
  <table width="900" border="1" align="center" cellpadding="0" cellspacing="0" class="manh">
    <tr>
      <td height="30" align="center" class="dangkythanhvien"><strong>Quên Mật Khẩu</strong></td>
    </tr>
    <tr>
      <td height="30" align="center"><strong>User</strong>
<input name="user" type="text" id="user" value="<?php  echo $_POST["user"];   ?>" /> </td>
    </tr>
    <tr>
      <td height="40" align="center"><input name="quenmk" type="submit" class="nutdangnhap" id="quenmk" value="Quên mật khẩu" /></td>
    </tr>
  </table>
</form>
</body>
</html>